<?php
class Pageley_Imaging_Shape_Rectangle implements Pageley_Imaging_Shape {
    
    private $width;
    private $height;
    
    public function __construct($width, $height) {
        $this->width = $width;
        $this->height = $height;
    }
    
    public function draw($brush, $resource, $x, $y) {
        $colorId = $brush->getColorId($resource);
        $success = imagefilledrectangle($resource, $x, $y, $x + $this->width - 1, $y + $this->height - 1, $colorId);
        if(!$success) {
            throw new Pageley_Util_IllegalArgumentException("Could not draw rectangle");
        }
    }
    
    public function __toString() {
        return "rectangle(" . $this->width . ", " . $this->height . ")";
    }
}